﻿using System.Linq;
using System.Web.DomainServices;
using System.Web.DomainServices.Providers;
using System.Web.Ria;
using System.Web.Security;
using SoftSource.Timecard.Web.Data;
using SoftSource.Timecard.Web.Resources;

namespace SoftSource.Timecard.Web.Services
{
    [EnableClientAccess]
    [RequiresAuthentication]
    public class StaticService : LinqToSqlDomainService<StaticDBDataContext>
    {
        public IQueryable<BillingFrequency> GetBillingFrequencies()
        {
            return this.DataContext.BillingFrequencies;
        }

        public IQueryable<BillingState> GetBillingStates()
        {
            return this.DataContext.BillingStates;
        }

        public IQueryable<ProjectStatus> GetProjectStatus()
        {
            return this.DataContext.ProjectStatus;
        }

        public IQueryable<ProjectType> GetProjectTypes()
        {
            return this.DataContext.ProjectTypes;
        }

        public IQueryable<Report> GetReports()
        {
            if (Roles.IsUserInRole(AuthenticationDataResources.ProjectManagerRole))
            {
                // Weekly Summary, Unapproved Entries, and Project Summary
                // TODO - Move this into a stored procedure
                return this.DataContext.Reports.Where(report => report.IsActive && (report.ReportID == 13 || report.ReportID == 14 || report.ReportID == 17));
            }
            else
            {
                return this.DataContext.Reports.Where(report => report.IsActive);
            }
        }

        public IQueryable<RevenueType> GetRevenueTypes()
        {
            return this.DataContext.RevenueTypes;
        }

        public IQueryable<Role> GetRoles()
        {
            return this.DataContext.Roles;
        }

        public IQueryable<UserType> GetUserTypes()
        {
            return this.DataContext.UserTypes;
        }
    }
}


